Skip to content

Change Orientation2D type to Rotary#264

Merged
waynemwashuma merged 5 commits intowimaengine:devfrom
waynemwashuma:change-orientation-2d-type
Sep 20, 2025
Merged

Change Orientation2D type to Rotary#264
waynemwashuma merged 5 commits intowimaengine:devfrom
waynemwashuma:change-orientation-2d-type

Conversation

@waynemwashuma
Copy link
Collaborator

@waynemwashuma waynemwashuma commented Sep 20, 2025

Objective

Refactors the entire rotation and orientation system to use quaternion-like Rotary instead of raw angles for 2D rotations. This provides more robust mathematical operations, eliminates angle wrapping issues, and creates consistency between 2D and 3D rotation handling.

Solution

  • Orientation2D now uses Rotary instead of Angle
  • Added Rotary.slerp() for smooth interpolation

Showcase

The new Rotary-based system provides more robust rotation handling:

// Creating orientations with Rotary
const orientation = new Orientation2D(Math.cos(angle), Math.sin(angle))

// Rotating objects properly
orientation.multiply(Rotary.fromAngle(QUARTER_PI * delta))

// Smooth interpolation between rotations
Rotary.slerp(startOrientation, endOrientation, progress)

Migration Guide

Orientation2D is no longer an Angle but a Rotary.Orientation operations should be switched from using number based angles to Rotary operations.For examole:

  • Rotating an entity:
// before:
orientation.value += rotationSpeed * deltaTime

// after
orientation.multiply(Rotary.fromAngle(rotationSpeed * deltaTime))

// Or for direct angle assignment
orientation.copy(Rotary.fromAngle(desiredAngle))
  • Getting the angle of the entity:
// before
const angle = orientation.value

// after
const angle = Rotary.toAngle(orientation)
  • Interpolation of orientation:
// before
Angle.lerp(startAngle, endAngle, t)

// after
Rotary.slerp(startOrientation, endOrientation, t)

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 20, 2025
@waynemwashuma waynemwashuma changed the title Change orientation 2d type Change Orientation2D type to Rotary Sep 20, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 20, 2025 22:13
@waynemwashuma waynemwashuma merged commit 3409550 into wimaengine:dev Sep 20, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the change-orientation-2d-type branch September 20, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant